package com.example.dnm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dnm.dao.MenuDao;
import com.example.dnm.pojo.Menu;
import com.example.dnm.service.MenuService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private  MenuDao menuDao;
    @Override
    public List<Menu> findAllMenu(Menu menu) {
        if (menu.getPage()!=null&&menu.getSize()!=null)
        {
            PageHelper.startPage(menu.getPage(),menu.getSize());
        }
        QueryWrapper<Menu> menuQueryWrapper = new QueryWrapper<>();
        List<Menu> list=menuDao.selectList(menuQueryWrapper);
        return list;
    }

    @Override
    public Menu findMenuByName(Menu menu) {
        return menuDao.selectOne(new QueryWrapper<Menu>().eq("menuid",menu.getMenuid()));
    }

    @Override
    public int addMenu(Menu menu) {
        return menuDao.insert(menu);
    }

    @Override
    public Menu finMenuById(Menu menu) {
        return menuDao.selectById(menu.getId());
    }

    @Override
    public int editMenu(Menu menu) {
        return menuDao.updateById(menu);
    }

    @Override
    public int deleteMenu(Menu menu) {
        return menuDao.deleteById(menu.getId());
    }
}
